package com.example.nfc.server;

import android.content.Context;

import com.example.nfc.server.network.http.HttpException;
import com.example.nfc.server.request.CardRequest;
import com.example.nfc.server.request.DuiKa;
import com.example.nfc.server.request.User;
import com.example.nfc.server.response.Card;
import com.example.nfc.server.response.ListCate;
import com.example.nfc.server.response.Respone;

import java.util.List;


@SuppressWarnings("deprecation")
public class APIAction extends BaseAction {


    /**
     * 构造方法
     *
     * @param context 上下文
     */
    public APIAction(Context context) {
        super(context);
    }

    /**
     * 登录
     * @param user
     * @param <T>
     * @return
     * @throws HttpException
     */
    public <T>T loginRequest(User user) throws HttpException {
        return (T)post("privilege.php?act=signin_mobile&type="+user.getType()+"&is_ajax=1", Respone.class,user);
    }

    /**
     * 获取token
     * @param <T>
     * @return
     * @throws HttpException
     */
    public <T>T getTokenRequest() throws HttpException {
        return (T)get("privilege.php?act=get_token&is_ajax=1", Respone.class,null);
    }

    /**
     * 获取token
     * @param <T>
     * @return
     * @throws HttpException
     */
    public <T>T getLogoutRequest() throws HttpException {
        return (T)get("privilege.php?act=logout_moblie&is_ajax=1", Respone.class,null);
    }

    /**
     *  获取卡片
     * @param <T>
     * @return
     * @throws HttpException
     */
    public <T>T getCardRequest(String cardId) throws HttpException {
        return (T)get("zc_project.php?act=get_add&card_id="+cardId, Card.class,null);
    }

    /**
     * 获取卡片分类
     * @param <T>
     * @return
     * @throws HttpException
     */
    public <T>T getCardCateRequest() throws HttpException {
        return (T)get("zc_project.php?act=get_cate", ListCate.class,null);
    }

    /**
     * 保存卡片
     * @param request
     * @param <T>
     * @return
     * @throws HttpException
     */
    public <T>T saveCardRequest(CardRequest request) throws HttpException {
        return (T)post("zc_project.php?act=save_mobile", Respone.class,request);
    }

    /**
     * 批量保存
     * @param request
     * @param <T>
     * @return
     * @throws HttpException
     */
    public <T>T saveCardRequest(List<CardRequest> request) throws HttpException {
        return (T)post("zc_project.php?act=save_list_mobile", Respone.class,request);
    }

    /**
     *  兑卡
     * @param request
     * @param <T>
     * @return
     * @throws HttpException
     */
    public <T>T duikaRequest(DuiKa request) throws HttpException {
        return (T)post("zc_project.php?act=duika_mobile", Respone.class,request);
    }

    /**
     *  兑卡检测
     * @param request
     * @param <T>
     * @return
     * @throws HttpException
     */
    public <T>T duikaCheckRequest(DuiKa request) throws HttpException {
        return (T)post("zc_project.php?act=duika_check_mobile", Respone.class,request);
    }

    /**
     *  批量兑卡
     * @param request
     * @param <T>
     * @return
     * @throws HttpException
     */
    public <T>T duikaRequest(List<DuiKa> request) throws HttpException {
        return (T)post("zc_project.php?act=duika_list_mobile", Respone.class,request);
    }
}
